﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Input.DeathModelsinput;
using IntelligentAgriculture.Contracts.Dto.Input.EarTagInput;
using IntelligentAgriculture.Contracts.Dto.Output.DeathModelsOutPut;
using IntelligentAgriculture.Contracts.Dto.Output.EarTagOutput;
using IntelligentAgriculture.Contracts.Dto.Output.PageOutput;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.DeathModelCommand;
using IntelligentAgriculture.WebAPI.Application.Command.EarTageCommand;
using IntelligentAgriculture.WebAPI.Application.Command.EliminationModelCommand;
using IntelligentAgriculture.WebAPI.Application.Command.RidgepCpoamd;
using IntelligentAgriculture.WebAPI.Application.Command.SheepAblactationCommand;
using IntelligentAgriculture.WebAPI.Application.CommandHandler.DepartMentCommandHandier;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 死淘管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeathModelController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数。
        /// </summary>
        /// <param name="mediator">用于中介调解模式的中介器实例，用于处理请求和发送命令。</param>
        public DeathModelController(IMediator mediator)
        {
            _mediator = mediator;
        }





        /// <summary>
        /// 根据耳号获取档案表
        /// </summary>
        /// <param name="earTagNumber"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<List<Sheepfilemodel>>> GetBuildByEar(string earTagNumbe)
        {
            var command = new DeathModelsCommand(earTagNumbe);
            return await _mediator.Send(command);
        }


        //[HttpGet]
        //public async Task<Results<List<Eartag>>> GetEweEarTagsFromSheepFile()
        //{
        //    var command = new GetEweEarTagsFromSheepFileCommand();
        //    return await _mediator.Send(command);
        //}


        [HttpGet]
        public async Task<Results<List<Eartag>>> GetEweEarTagsFromSheepFile()
        {
            var command = new DeathEagCommand();
            return await _mediator.Send(command);
        }


        /// <summary>
        /// 死亡新增
        /// </summary>
        /// <param name="coomand">添加实体</param>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<Results<int>> AddManager(List<Deathmodel> coomand)
        {
            try
            {
                var command = new DeathEagAddCommand(coomand);
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 死亡原因
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public object Showcause()
        {
            List<object> list = new List<object>();
            foreach (CauseofdeathDTO item in Enum.GetValues(typeof(CauseofdeathDTO)))
            {
                list.Add(new
                {
                    name = item.ToString(),
                    Value = item
                });
            }
            return Results<object>.DataResult(list);
        }


        /// <summary>
        /// 死亡显示分页查询
        /// </summary>
        /// <param name="input">输入参数，用于指定查询条件</param>
        /// <returns>返回一个包含查询结果的异步任务结果</returns>
        [HttpGet]
        public async Task<Results<PagesOutput<DeathModelsOutPut>>> GetShow([FromQuery] DeathModelInput? input)
        {
            try
            {
                var list = new DeathEagShowCommand(input);
                return await _mediator.Send(list);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 死亡单个逻辑删除处理删除耳标命令的 HTTP DELETE请求。
        /// </summary>
        /// <param name="command">包含要删除的耳标信息的命令对象</param>
        /// <returns>一个表示操作结果的异步任务，返回删除操作的结果</returns>
        [HttpDelete]
        public async Task<Results<int>> Delete(DeathEagDeleteCommand command)
        {
            try
            {
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }


        


        /// <summary>
        /// 死亡批量逻辑删除 HTTP DELETE 方法发送的批量删除命令
        /// </summary>
        /// <param name="command">包含要执行批量删除操作的命令对象</param>
        /// <returns>一个表示操作结果的异步任务，返回批量删除操作的结果</returns>
        [HttpPut]
        public async Task<Results<int>> DeleteRange(DeathEagDeleteRangsCommand command)
        {
            try
            {
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }





        /// <summary>
        /// 反填功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<DeathModelsOutPut>> GetFind(int id)
        {
            try
            {
                var command = new DeathEagFindCommand(id);
                var roles = await _mediator.Send(command);
                return roles;
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 修改死亡表
        /// </summary>
        /// <param name="command">耳标实体</param>
        /// <returns>受影响的行数</returns>
        [HttpPost]
        public async Task<Results<int>> UpdateStart(DeathEagUpdateCommand command)
        {
            try
            {
                return await _mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }




        





    }
}
